Vue.component('Detail', {
	template: `
		<el-dialog title="查看跟单" width="" class="icon-dialog" :visible.sync="show" @open="open" :before-close="closeForm" append-to-body>
			<table cellpadding="0" cellspacing="0" class="table table-bordered" align="center" width="100%" style="word-break:break-all; margin-bottom:30px;  font-size:13px;">
				<tbody>
					<tr>
						<td class="title" width="100">资源添加时间：</td>
						<td>
							{{parseTime(form.add_time,'{y}-{m}-{d} {h}:{i}:{s}')}}
						</td>
					</tr>
					<tr>
						<td class="title" width="100">电话录入时间：</td>
						<td>
							{{parseTime(form.mobile_time,'{y}-{m}-{d} {h}:{i}:{s}')}}
						</td>
					</tr>
					<tr>
						<td class="title" width="100">联系人：</td>
						<td>
							{{form.name}}
						</td>
					</tr>
					<tr>
						<td class="title" width="100">资源描述：</td>
						<td>
							{{form.info}}
						</td>
					</tr>
					<tr>
						<td class="title" width="100">租金转让：</td>
						<td>
							{{form.sell}}
						</td>
					</tr>
					<tr>
						<td class="title" width="100">面积：</td>
						<td>
							{{form.area}}
						</td>
					</tr>
					<tr>
						<td class="title" width="100">区域：</td>
						<td>
							{{form.regoin}}
						</td>
					</tr>
					<tr>
						<td class="title" width="100">联系地址：</td>
						<td>
							{{form.contact_address}}
						</td>
					</tr>
					<!--
					<tr>
						<td class="title" width="200">电话二维码：</td>
						<td>
							<el-image v-if="form.img" class="table_list_pic" :src="form.img"  :preview-src-list="[form.img]" style="width:200px;height:200px"></el-image>
						</td>
					</tr>
					-->
					<!--
					<tr>
						<td class="title" width="100">首次资源地址：</td>
						<td v-on:click="copy(form.url)">
							点击复制网址在浏览器地址粘贴打开
						</td>
					</tr>
					-->
					<tr>
					    <td class="title" width="100">打开首发资源：</td>
					    
					    <td><el-link :href="form.url" target="_blank" class="buttonText"  type="primary" :underline="false">直接点击</el-link></td>
					  
					</tr>
					<tr>
					    <td class="title" width="100">查找电话</td>
					    
					    <td><el-link :href="form.baiduMapUrl" target="_blank" class="buttonText" type="primary" :underline="false">百度地图</el-link></td>
					    <td><el-link :href="form.gaodeMapUrl" target="_blank" class="buttonText"  type="primary" :underline="false">高德地图</el-link></td>
					    
					</tr>
					<!--
					<tr>
						<td class="title" width="100">呼叫系统信息状态：</td>
						<td>
							<span style="color: red">{{voip.connectInfo}}:</span><span>{{voip.callInfo}}</span>
						</td>
					</tr>
					<tr >
						<td class="title" width="100">一键呼叫：</td>
						<td><el-button v-on:click="click_test" style="color: #FFFFFF;background-color:#409EFF;border-color:#409EFF">拨打</el-button></td>
					</tr>
					-->
					<tr>
						<td class="title" width="100">保护客户：</td>
						<td>
							<span v-if="form.connection_type[0] == '1'" style="color:red">保护客户({{form.user_name}})</span>
							<span v-if="form.connection_type[1] == '1'" style="color:red">保护客户({{form.user_name}})</span>
						</td>
					</tr>
				
				</tbody>
			</table>
			
		<el-form :size="size" ref="form" :model="form" :rules="rules" :label-width=" ismobile()?'90px':'16%'">
			
			<el-row >
				<el-col :span="24">
					<el-form-item label="手机号码" prop="mobile">
						<el-input  v-model="form.mobile" autoComplete="off" clearable  placeholder="请输入手机号码"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<!--	
			<el-row >
				<el-col :span="24">
					<el-form-item label="微信号" prop="weixin">
						<el-input  v-model="form.weixin" autoComplete="off" clearable  placeholder="请输入微信号"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
            -->
		    <el-row >
				<el-col :span="24">
					<el-form-item label="进展" prop="evolve">
						<el-select style="width:100%" v-model="form.evolve" filterable clearable placeholder="请选择进展">
							<el-option key="0" label="待访问客户" :value="1"></el-option>
							<el-option key="1" label="考虑客户" :value="2"></el-option>
							<el-option key="2" label="无效客户" :value="3"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
			</el-row>

			<el-row >
				<el-col :span="24">
					<el-form-item label="客户类型" prop="connection_type">
						<el-checkbox-group v-model="form.connection_type">
							<el-checkbox key="0" label="1">保护客户</el-checkbox>
						</el-checkbox-group>
					</el-form-item>
				</el-col>
			</el-row>
			<!--
			<el-row >
				<el-col :span="24">
					<el-form-item label="保护客户备注" prop="back">
						<el-input  v-model="form.back" autoComplete="off" clearable  placeholder="请输入备注"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			-->
			<!--
		    <el-row >
				<el-col :span="24">
					<el-form-item label="跟单方式" prop="documentary_mothod">
						<el-select style="width:100%" v-model="form.documentary_mothod" filterable clearable placeholder="请选择跟单方式">
							<el-option key="0" label="电话沟通" :value="1"></el-option>
							<el-option key="1" label="微信交流" :value="2"></el-option>
							<el-option key="2" label="QQ/旺旺" :value="3"></el-option>
							<el-option key="3" label="电子邮箱" :value="4"></el-option>
							<el-option key="4" label="上门拜访" :value="5"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
			</el-row>
		    -->
			<el-row >
				<el-col :span="24">
					<el-form-item label="跟单详情" prop="documentary_info">
						<el-input  type="textarea" autoComplete="off" v-model="form.documentary_info"  :autosize="{ minRows: 2, maxRows: 4}" clearable placeholder="请输入跟单详情"/>
					</el-form-item>
				</el-col>
			</el-row>
			
			<el-table :row-class-name="rowClass"  @row-click="handleRowClick"  row-key="id"  :header-cell-style="{ background: '#eef1f6', color: '#606266' }" @sort-change='sortChange' v-loading="loading"  ref="multipleTable" border class="eltable" :data="list"  style="width: 100%">
			
            	<el-table-column align="center"  property="add_time"  label="跟单时间" show-overflow-tooltip width="150px">
            		<template slot-scope="scope">
            			{{parseTime(scope.row.add_time)}}
            		</template>
            	</el-table-column>
        		<el-table-column align="center"  property="contacts"  label="跟单人" show-overflow-tooltip width="100px">
	            </el-table-column>
            	<el-table-column align="center"  property="documentary_info"  label="跟单详情" show-overflow-tooltip width="">
	            </el-table-column>
			</el-table>
			
		</el-form>
		
			<div slot="footer" class="dialog-footer">
				<el-button :size="size" :loading="loading" type="primary" @click="submit" >
					<span v-if="!loading">保存</span>
					<span v-else>提 交 中...</span>
				</el-button>
				<el-button :size="size" @click="closeForm">取 消</el-button>
			</div>
		</el-dialog>
	`
	,
	props: {
		show: {
			type: Boolean,
			default: true
		},
		size: {
			type: String,
			default: 'mini'
		},
		info: {
			type: Object,
		},
	},
	data(){
		return {
			form: {
				add_time:'',
				mobile_time:'',
				name:'',
				mobile:'等待录入',
				info:'',
				sell:'',
				area:'',
				floor:'',
				regoin:'',
				contact_address:'',
				type:'',
				property_type:'',
				lease_term:'',
				specs:'',
				deposit:'',
				click:'0',
				documentary_info:'',
				connection_type:[],
				url:'',
				evolve:1,
				need_type:'',
				weixin:'',
				img:'',
				back:'',
				gaodeMapUrl:'',
				baiduMapUrl:'',
			},
			loading:false,
			rules: {
				documentary_info:[
					{required: true, message: '跟单详情不能为空', trigger: 'blur'},
				],
				evolve:[
					{required: true, message: '进展不能为空', trigger: 'change'},
				],
			},
			voip:{},
			connectStatus:'',
			phonestatus:'',
			passMd5:'',
			user_call:{},
			list: [],
			ids: [],
		}
	},
	methods: {
		open(){
			axios.post(base_url+'/Resource/detail',this.info).then(res => {
				this.form = res.data.data
				this.form.baiduMapUrl = 'https://map.baidu.com'
				this.form.gaodeMapUrl = 'https://www.amap.com'
				this.user_call = res.data.user_call
				this.list = res.data.documentary
				console.log(this.documentary)
				// this.$emit('refesh_list')
				this.setDefaultVal('connection_type')

                /*
				this.voip = this.voipCall()
				this.voip.CallBack_login = function(code){
					if(code==0){
						return '链接成功'
					}else{
						return '链接失败'
					}
				}

				//处理显示信息
				this.voip.CallUserInfo = function(olduser,newuser){
					console.log(101)
					console.log(newuser)
					var bb = olduser==null||olduser.waterLine<newuser.waterLine;
					if(newuser.phoneStatus==0||newuser.phoneStatus==1){
						if(olduser!=null&&olduser.waterLine<newuser.waterLine&&(olduser.phone!=null&&olduser.phone!="")){
							var peer = '呼出';
							if(olduser.phonepeer==2){
								peer = '呼入';
							}
							return "电话："+olduser.phone+"已挂机,cdrId:"+olduser.cdrId+",方向："+peer;
							//$("#popupscreendiv").append("电话："+olduser.phone+"已挂机,cdrId:"+olduser.cdrId+",方向："+peer);
						}else if((newuser.phone==""||newuser.phone==null)&&newuser.phoneStatus==0){
							return "空闲状态,可以拔打新的电话";
						}
					}else if(bb){
						if(olduser!=null&&olduser.phone!=newuser.phone&&olduser.phone!=""&&newuser.phoneStatus>=3){
							var peer = '呼出';
							if(olduser.phonepeer==2){
								peer = '呼入';
							}
							return "电话："+olduser.phone+"已挂机,cdrId:"+olduser.cdrId+",方向："+peer;
							//$("#popupscreendiv").append("电话："+olduser.phone+"已挂机,cdrId:"+olduser.cdrId+",方向："+peer);
						}
						var peer = '呼出';
						if(newuser.phonepeer==2){
							peer = '呼入';
						}
						switch(newuser.phoneStatus){
							case 3: return "电话："+newuser.phone+"拨号,方向："+peer;
								break;
							case 4: return "电话："+newuser.phone+"呼出响铃,方向："+peer;
								break;
							case 5: return "电话："+newuser.phone+"呼入响铃,方向："+peer;
								break;
							case 6: return "电话："+newuser.phone+"接通,方向："+peer;
								break;
							case 7: return "电话："+newuser.phone+"忙,正在通话";
								break;
						}
						//$("#popupscreendiv").append("电话："+newuser.phone+"已挂机,phoneStatus:"+newuser.phoneStatus+",方向："+peer);
					}
				}

				//初始化数据
				this.voip.init('https://ai.800ing.com/')
				this.voip.userlogin(this.user_call.username,this.user_call.passMd5)
				*/
			})
		},

		submit(){
			this.$refs['form'].validate(valid => {
				if(valid) {
					this.loading = true
					axios.post(base_url + '/Resource/documentary',this.form).then(res => {
						if(res.data.status == 200){
							this.$message({message: res.data.msg, type: 'success'})
							this.$emit('refesh_list')
							this.closeForm()
						}else{
							this.loading = false
							this.$message.error(res.data.msg)
						}
					}).catch(()=>{
						this.loading = false
					})
				}
			})
		},
		sortChange(val){
			if(val.order == 'descending'){
				this.order= 'desc'
			}
			if(val.order == 'ascending'){
				this.order= 'asc'
			}
			this.sort = val.prop
			this.index()
		},
		rowClass ({ row, rowIndex }) {
			for(let i=0;i<this.ids.length;i++) {
				if (row.id === this.ids[i]) {
					return 'rowLight'
				}
			}
		},
		handleRowClick(row, rowIndex,event){
			if(event.target.className !== 'el-input__inner'){
				this.$refs.multipleTable.toggleRowSelection(row)
			}
		},
		setDefaultVal(key){
			if(this.form[key] == null || this.form[key] == ''){
				this.form[key] = []
			}
		},
		closeForm(){
			this.$emit('update:show', false)
			this.loading = false
			if (this.$refs['form']!==undefined) {
				this.$refs['form'].resetFields()
			}
		},
		
		copy(copys){
			let url = copys;
			let oInput = document.createElement('input');
			oInput.value = url;
			document.body.appendChild(oInput);
			oInput.select(); // 选择对象;
			console.log(oInput.value)
			document.execCommand("Copy"); // 执行浏览器复制命令
			this.$message({
				message: '复制成功',
				type: 'success'
			});
			oInput.remove()
			
		},
		
		/*
		voipCall(){
			var oVoip = new Object;
			oVoip.getNowTimes = function(){
				var mydate = new Date();
				return mydate.getTime();
			}
			oVoip.GetRandomNum = function(Min, Max) {
				var Range = Max - Min;
				var Rand = Math.random();
				return(Min + Math.round(Rand * Range));
			}
			oVoip.connectInfo = "";
			oVoip.callInfo = "";
			oVoip.userSession = "";
			oVoip.userName = "";
			oVoip.userPass = "";
			oVoip.extension = "";
			oVoip.exteId = 0;
			oVoip.userId = 0;
			oVoip.compId = 0;
			oVoip.ExteDialType=0;
			oVoip.exteLoginType=0;
			oVoip.lastWatertime = oVoip.getNowTimes();
			oVoip.Waterline = 0;
			oVoip.CallBack_Call = function(kind,phone){};
			oVoip.CallBack_Answer = function(kind,phone){};
			oVoip.CallBack_HangUp = function(kind,phone,obj){};
			oVoip.CallBack_login = null;
			oVoip.CallBack_status = function(msg){};
			oVoip.CallBack_Key = function(keylist){};
			oVoip.CallUserInfo = function(oldUser,userInfo){};
			oVoip.Service_Call = function(phone){
				alert('呼叫电话：'+phone);
			};
			oVoip.ShowMsg = null;
			oVoip.status = -1;
			oVoip.kind = 1;
			oVoip.oldUser = null;
			oVoip.tcpWssPort = 0;
			oVoip.tcpWsPort = 0;
			oVoip.webTcpSocket = null;
			oVoip.lineId = oVoip.GetRandomNum(100,21323322);
			oVoip.phone = null;
			//用户登录
			oVoip.init = function(url){
				oVoip.serviceUrl = url;
			};
			oVoip.TransferUser = function(phone,func){
				var url = this.getUrl(oVoip.userName,oVoip.userPass,"transferExten");
				this.getJsonP(url,{descExten:phone},function(data) {
					func(data);
				});
			};
			oVoip.setUserCheckInOut = function(aStatus,fun){
				var url = this.getUrl(oVoip.userName,oVoip.userPass,"setUserCheckInOut");
				this.getJsonP(url,{status:aStatus},function(data) {
					fun(data);
				});
			};
			oVoip.CallPhone = function(phone,func){
				if(phone==null||phone.length<3){
					return;
				}
				var url = this.getUrl(oVoip.userName,oVoip.userPass,"callbackPhone");
				//		url+='&paramvalue='+$('#paramvalue').val();
				this.getJsonP(url,{sourcePhone:oVoip.userName,descPhone:phone},function(data) {
					func(data);
				});
			};
			oVoip.hangup = function(phone,func){
				var url = this.getUrl(oVoip.userName,oVoip.userPass,"hangupExten");
				this.getJsonP(url,{phoneNum:phone},function(data) {
					func(data);
				});
			}
			oVoip.userlogin = function(userName,userpass){
				var url = this.getUrl(userName,userpass,"getExtension");
				oVoip.getJsonP(url,{},function(data) {
					if(data.code==0){
						oVoip.userSession = data.sessionId;
						oVoip.exteId = data.exteId;
						oVoip.compId = data.compId;
						oVoip.lineId = data.loginLine;
						oVoip.extension = data.extension.substr(0, 6);
						oVoip.userName = userName;
						oVoip.userId = data.extension;
						oVoip.userPass = userpass;
						oVoip.exteLoginType = data.exteLoginType;
						oVoip.ExteDialType = data.ExteDialType;
						oVoip.connectInfo = oVoip.CallBack_login(0,"");
						oVoip.tcpWssPort = data.tcpWssPort;
						oVoip.tcpWsPort = data.tcpWsPort;
						oVoip.initSocket(data.host);
						oVoip.getLoadmonitor();
					}else{
						oVoip.userSesson = "";
						oVoip.exteId = 0;
						oVoip.compId = 0;
						oVoip.userName = "";
						oVoip.userPass = "";
						oVoip.connectInfo = oVoip.CallBack_login(1,data.message);
					}
				});
			};
			oVoip.getLoadmonitor = function(){
				var url = oVoip.serviceUrl + 'voip/extensionmanager/loadmonitor.jsonp?callback=?&sessionId='+oVoip.userSession+"&extension="+oVoip.userName;
				this.getJsonP(url,{},function(data) {
					if(data.code==0&&data.rows!=null&&data.rows.length>0){
						oVoip.CallBack_status(data.rows[0]);
					}
					setTimeout(function(){oVoip.getLoadmonitor()},60000);
				});
			};
			oVoip.initSocket = function(host){
				if(window.location.protocol=='https:'){
					if(oVoip.tcpWssPort!=0){
						var wsUrl = "wss://"+host+":" +(oVoip.tcpWssPort);
						oVoip.webTcpSocket = new this.WebTcpSocket();
						oVoip.webTcpSocket.initSocket(wsUrl,oVoip.userId,oVoip.doHandUpMsg);
					}else{
						oVoip.getLongWaterLine();
					}
				}else if(oVoip.tcpWsPort!=0){
					var wsUrl = "ws://"+host + ":" +(oVoip.tcpWsPort);
					oVoip.webTcpSocket = new this.WebTcpSocket();
					oVoip.webTcpSocket.initSocket(wsUrl,oVoip.userId,oVoip.doHandUpMsg);
				}else{
					oVoip.getLongWaterLine();
				}
			};
			//取服务器是否发生变化
			oVoip.getLongWaterLine = function(){
				oVoip.lastWatertime = this.getNowTimes();
				var url = this.getUrl(oVoip.userName,oVoip.userPass,"getLongWaterLine");
				this.getJsonP(url,{client:1,message:1,loginLine:oVoip.lineId},function(data) {
					if(data!=null&&data.code==0){
						if(data.waterline>oVoip.Waterline){
							if(oVoip.Waterline==0){
								oVoip.Waterline = data.waterline - 1;
							}
							if(data.msgs!=null){
								oVoip.HandleMsg(data.msgs);
							}
						}
						if(data.userInfo!=null){
							oVoip.callInfo = oVoip.CallUserInfo(oVoip.oldUser,data.userInfo);
							oVoip.oldUser = data.userInfo;
						}
						if(data&&oVoip.CallBack_Key&&data.keylist){
							oVoip.CallBack_Key(data.keylist);
						}
					}
					oVoip.getLongWaterLine();
				});
			};
			//接收消息
			oVoip.getMsgList = function(){
				var url = this.getUrl(oVoip.userName,oVoip.userPass,"recvMsg");
				var aLimit = 9876;
				if(oVoip.Waterline>0){
					aLimit = 5;
				}
				this.getJsonP(url,{waterLine:oVoip.Waterline,client:1,limit:aLimit},function(data) {
					if(data.code==0&&data.msgs!=null&&data.msgs.length>0){
						oVoip.HandleMsg(data.msgs);
					}
				});
			};
			oVoip.HandleMsg = function(msg){
				for (var i = 0; i < msg.length; i++) {
					var obj = msg[i];
					if (oVoip.Waterline<obj.waterLine) {
						oVoip.doHandUpMsg(obj);
					}
				}
			}
			oVoip.doHandUpMsg = function(obj){
				oVoip.Waterline = obj.waterLine;
				if (true) {
					var status = 0;
					var cdrId = 0;
					try{
						context = eval('(' + obj.content + ')');
						status = context.status;
						cdrId = context.cdrId;
						try{
							var nn = parseInt(context.status);
							status = nn;
						}catch(ee){

						}
					}catch(err){
						//return;
					}
					//if(obj.phone!=null&&obj.phone.length==3){
					//	obj.phone = oVoip.extension+obj.phone;
					//}
					if(obj.kind==1||obj.kind==2){
						if(oVoip.phone!=obj.phone&&status==0){
							oVoip.CallBack_Call(obj.kind,obj.phone);
							oVoip.phone = obj.phone;
							oVoip.kind = obj.kind;
							oVoip.status = 0;
						}else if(oVoip.status<status){
							oVoip.status = status;
							switch (status) {
								case (0):
									oVoip.CallBack_Call(obj.kind,obj.phone);
									oVoip.phone = obj.phone;
									oVoip.kind = obj.kind;
									break;
								case (1):
									oVoip.CallBack_Answer(obj.kind,oVoip.phone);
									break;
								case (2):
									oVoip.getHandUpMsg(obj.phone,oVoip.kind,cdrId);
									oVoip.status = -1;
									break;
							}
						}
					}else if(obj.kind==10&&obj.client==0){
						oVoip.Service_Call(obj.phone);
					}else if(obj.kind>2&&oVoip.ShowMsg!=null){
						oVoip.callInfo = oVoip.ShowMsg(obj);
					}
				}
			}
			oVoip.getHandUpMsg = function(phone,kind,aCdrId){
				if(aCdrId==-1){
					var obj = new Object;
					obj.cdrId = aCdrId;
					obj.cdrPeer=kind;
					oVoip.CallBack_HangUp(kind,phone,obj);
				}else{
					var url = this.getUrl(oVoip.userName,oVoip.userPass,"findDialrecord");
					if(phone!=null&&phone.length<5){
						phone = oVoip.extension+phone;
					}
					this.getJsonP(url,{phoneNum:phone,limit:1,extension:oVoip.userName,scdrId:aCdrId},function(data) {
						if(data.code==0&&data.rows!=null&&data.rows.length>0){
							var obj = data.rows[0];
							oVoip.CallBack_HangUp(kind,phone,obj);
						}else{
							var obj = new Object;
							obj.cdrId = aCdrId;
							obj.cdrPeer=kind;
							oVoip.CallBack_HangUp(kind,phone,obj);
						}
					});
				}

			};
			oVoip.answerPhone = function(phone,func){
				var url = this.getUrl(oVoip.userName,oVoip.userPass,"sendMsg");
				this.getJsonP(url,{phone:phone,kind:6,client:1,lostTime:10},function(data) {
					func(data);
				});
			}
			oVoip.StopPhone = function(phone,func){
				var url = this.getUrl(oVoip.userName,oVoip.userPass,"sendMsg");
				this.getJsonP(url,{phone:phone,kind:7,client:1,lostTime:10},function(data) {
					func(data);
				});
			}

			oVoip.getChannelList = function(func){
				var url = this.getUrl(oVoip.userName,oVoip.userPass,"getChannelList");
				this.getJsonP(url,{queueSize:1},function(data) {
					func(data);
				});
			}

			oVoip.getUrl = function(user,pass,funcname){
				var url=oVoip.serviceUrl+'voip/api/jsonpdata.jsonp?callback=?&method='+funcname+'&sa_user='+user+'&sa_password='+pass+"&loginType=jsonpLogin";
				//var url=oVoip.serviceUrl+'voip/api/jsonpdata.jsonp?callback=?&method='+funcname+'&sa_user='+user+'&sa_password='+pass+"&loginType=jsonpLogin";
				// console.log(url)
				return url;
			}
			oVoip.timeoutevent = function(){
				var aTime = oVoip.getNowTimes();
				if(oVoip.exteId != 0&&aTime-oVoip.lastWatertime>1000*35){
					if(window.location.protocol=='https:'){
						if(oVoip.tcpWssPort==0){
							console.log(1)
							oVoip.getLongWaterLine();
						}
					}else if(oVoip.tcpWsPort==0){
						console.log(2)
						oVoip.getLongWaterLine();
					}
				}
			}
			setInterval(oVoip.timeoutevent, 1000);

			oVoip.WebTcpSocket = function(){
				var socket = new Object;
				socket.GetRandomNum_E = function(Min, Max) {
					var Range = Max - Min;
					var Rand = Math.random();
					return(Min + Math.round(Rand * Range));
				}
				socket.ip = '';
				socket.userId='';
				socket.WS = null;
				socket.sinterval = null;
				socket.loginstatus = 0;
				socket.lastLoginTime = 0;
				socket.lastHeartTime = 0;
				socket.randPort = socket.GetRandomNum_E(100000,999999);
				socket.MessageBack=function(msg){
					var ss = msg;
					console.log(JSON.stringify(ss));
				};
				socket.initSocket = function(aIp,aUserId,callMsg){
					socket.ip = aIp;
					socket.MessageBack = callMsg;
					socket.userId=aUserId;
					//socket.sinterval = setInterval(function(){socket.socketHeart()},200);

				};
				socket.init = function(){
					socket.WS = new WebSocket(socket.ip);
					socket.WS.onmessage=function(obj){
						console.log(socket.getCurrentTime()+'-->socket msg:'+obj.data);
						var data = $.parseJSON( obj.data );
						if(data!=null){
							if(data.cmd=='msg'){
								if(data&&socket.MessageBack){
									socket.MessageBack(data.content);
								}
							}else if(data.cmd=='heart'){
								socket.lastHeartTime = new Date().getTime();
							}else if(data.cmd=='login'){
								socket.loginstatus = 2;
							}
						}
					};
					socket.WS.onopen = function(){
						socket.loginstatus = 1;
					}
					socket.WS.onclose=function(e){
						socket.loginstatus = 0;
						console.log('断开原因：'+e.code+'--->'+e.reason);
						console.log(e);
						socket.WS=null;
					};
					socket.WS.onerror=function(error){
						socket.loginstatus = 0;
						console.log(error);
						socket.WS=null;
					}
				};
				socket.socketHeart = function(){
					let d = new Date().getTime();
					if(socket.loginstatus == 0&&socket.WS==null){
						socket.init();
					}
					if(socket.loginstatus == 1 && d-socket.lastLoginTime>1000*30 && socket.WS.readyState==WebSocket.OPEN){
						socket.lastLoginTime = d;
						socket.WS.send('{"cmd":"Login","rand":"'+socket.randPort+'","userId":"'+socket.userId+'","loginType":0}');
					}
					if(socket.loginstatus == 2 && d-socket.lastHeartTime>1000*14 && socket.WS.readyState==WebSocket.OPEN){
						socket.lastHeartTime = d;
						socket.WS.send('{"cmd":"Heartbeat"}');
					}
				};
				setInterval (function(){socket.socketHeart();},1000);
				socket.getCurrentTime = function(){
					var date = new Date();
					var yyyy = date.getFullYear();
					var month = this.repair(date.getMonth()+1);
					return yyyy+"-"+month+"-"+this.repair(date.getDate())+ " "+this.repair(date.getHours())
						+":"+this.repair(date.getMinutes())+":"+this.repair(date.getSeconds());
				}
				socket.repair = function(i){
					if(i<10){
						return "0"+i;
					}else{
						return i;
					}
				}

				return socket;
			}
			oVoip.getJsonP = function(url,parms,callback){
				$.getJSON(url,parms, function(data) {
					callback(data);
				});
			}
			return oVoip;
		},
		click_test(){
			var phone = this.form.mobile
			if(phone==null||phone.length<5){
				alert('号码错误')
			}
			this.voip.CallPhone(phone,function(data){
				if(data.code==0){
					alert('拔号成功')
				}else{
					alert(data.message)
				}
			});

		},
		*/

	}
})
